//
//  ViolationViewManage.m
//  carcareIOS
//
//  Created by ileo on 16/8/17.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "ViolationManage.h"
#import "MineCarsManager.h"

#import "ViolationCarsViewController.h"
#import "BRCarInfoViewController.h"
#import "ViolationInfoViewController.h"

@interface ViolationManage ()

@property (nonatomic, strong) MineCarsManager *mineCarsManager;



@end

@implementation ViolationManage

IMP_SINGLETON

- (instancetype)init
{
    self = [super init];
    if (self) {
        RACSignal *initStatusSignal = RACObserve(self.mineCarsManager, initStatus);
        RAC(self,initStatus) = initStatusSignal;
        __weak __typeof(self) wself = self;
        [initStatusSignal subscribeNext:^(NSNumber *x) {
            if ([x unsignedIntegerValue] == ManagerDataInitSuccess) {
                [wself updateViolations];
            }
        }];
    }
    return self;
}

-(void)updateViolations{
//    NSArray *cars = self.mineCarsManager.cars;
    
}

-(void)startFromViewController:(UIViewController *)viewController{
    ViolationCarsViewController *firVC = [[[ViolationCarsViewController alloc] initWithTableRefreshType:TYPE_TABLE_REFRESH_PULL_DOWN]navSetupBackItemWithIdentification:BACK_ICON_TITLE];
    [viewController.navigationController pushViewController:firVC animated:self.vioCarModels.count > 1];
    if (self.vioCarModels.count > 0) {
        VioCarModel *model = [self.vioCarModels firstObject];
        if (model.isVioInfoComplete) {
            ViolationInfoViewController *vc = [[[ViolationInfoViewController alloc] initWithTableRefreshType:TYPE_TABLE_REFRESH_PULL_DOWN] navSetupBackItemWithIdentification:BACK_ICON_TITLE];
            vc.vioCarModel = model;
            [viewController.navigationController pushViewController:vc animated:YES];
        }else{
            BRCarInfoViewController * vc = [[BRCarInfoViewController alloc] initWithInputType:TYPE_INPUT_TABLEVIEW vioCarModel:model];
            [viewController.navigationController pushViewController:vc animated:YES];
        }
    }else{
        BRCarInfoViewController * vc = [[BRCarInfoViewController alloc] initWithInputType:TYPE_INPUT_TABLEVIEW vioCarModel:nil];
        [viewController.navigationController pushViewController:vc animated:YES];
    }
}


@end
